<!-- 会员分类新增 -->
<template>
  <a-modal
    :maskClosable="false"
    :title="`${titleMap[type]}会员分类`"
    centered
    :width="800"
    v-model="visible"
    @ok="handleSubmit"
  >
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="{ span: 5 }" :wrapper-col="{ span: 16 }">
      <a-form-model-item label="会员分类名称" prop="name">
        <a-input v-model="form.name" />
      </a-form-model-item>
      <a-form-model-item label="会员类型">
        <a-select v-model="form.formType">
          <a-select-option v-for="item in memberLevelOption" :key="item.id">{{ item.name }}</a-select-option>
        </a-select>
      </a-form-model-item>
      <a-form-model-item label="是否对外显示">
        <a-switch v-model="form.enabled" />
      </a-form-model-item>
      <a-form-model-item label="排序" prop="sort">
        <a-input v-model="form.sort" />
      </a-form-model-item>
      <a-form-model-item label="备注">
        <a-textarea v-model="form.remark" :rows="4" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import { addMember } from '@/api/member/member'
import {} from '@/api/member/memberConfig'
export default {
  props: ['attacheList', 'memberLevelOption', 'applyType'],
  components: {},
  data() {
    return {
      visible: false,
      titleMap: {
        add: '新增',
        edit: '编辑',
      },
      type: 'add',
      form: {
        name: undefined,
        formType: undefined,
        enabled: undefined,
        sort: undefined,
        remark: undefined,
      },
      rules: {
        name: [{ required: true, message: '请输入会员分类名称', trigger: 'blur' }],
        formType: [{ required: true, message: '请选择会员类型', trigger: 'change' }],
        sort: [{ required: true, message: '请输入排序', trigger: 'blur' }],
      },
    }
  },
  computed: {},
  watch: {},
  methods: {
    show(data) {
      this.row = JSON.parse(data.row)
      this.type = data.type
      this.visible = true
    },
    async handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          let { code, msg } = await addMember({ ...this.form, applyType: this.applyType })
          if (code === 0) {
            this.$message.success(msg)
            this.$emit('success')
            this.visible = false
          } else if (code != 20001) {
            this.$message.error(msg)
          }
        }
      })
    },
  },
  created() {},
  mounted() {},
}
</script>
<style scoped>
</style>